<?php
namespace app\api\controller;
use think\Controller;
use think\Db;
class Backsale extends Base{
    public function backfee(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.order_id"))){
            $order_id=input("param.order_id");
        }else{
            return json(['code' => 502, 'msg' => '订单id呢']);exit();
        }
        if(!empty(input("param.openid"))){
            $openid=input("param.openid");
        }else{
            return json(['code' => 503, 'msg' => 'openid呢']);exit();
        }
        if(!empty(input("param.backreason"))){
            $backreason=input("param.backreason");
        }else{
            return json(['code' => 504, 'msg' => '理由呢']);exit();
        }
        if(!empty(input("param.backtype"))){
            $backtype=input("param.backtype");
        }else{
            return json(['code' => 505, 'msg' => '要求呢']);exit();
        }
        if(!empty(input("param.backstate"))){
            $backstate=input("param.backstate");
        }else{
            return json(['code' => 506, 'msg' => '复合要求呢']);exit();
        }
        $backcert=input("param.backcert");
        $data['backreason']=$backreason;
        $data['backstate']=$backstate;
        $data['backtype']=$backtype;
        $data['backcert']=$backcert;
        $data['paystate']=7;
        $data['salesbacktate']=1;
        $data['applytime']=time();
        $collect=Db::name('orders')->where('cus_id',$cus_id)->where('openid',$openid)->where('id',$order_id)->update($data);
        if($collect){
            Db::name('ordersub')->where('cus_id',$cus_id)->where('openid',$openid)->where('of_id',$order_id)->update($data);
            return json(['code' => 200, 'msg' => '申请成功！']);exit();
        }else{
            return json(['code' => 500, 'msg' => '失败！']);exit();
        }
    }
    public function expressinfo(){
        if(!empty(input("param.cus_id"))){
            $cus_id=input("param.cus_id");
        }else{
            return json(['code' => 501, 'msg' => '请给出客户id']);exit();
        }
        if(!empty(input("param.order_id"))){
            $order_id=input("param.order_id");
        }else{
            return json(['code' => 502, 'msg' => '订单id呢']);exit();
        }
        if(!empty(input("param.openid"))){
            $openid=input("param.openid");
        }else{
            return json(['code' => 503, 'msg' => 'openid呢']);exit();
        }
        if(!empty(input("param.expresscom"))){
            $expresscom=input("param.expresscom");
        }else{
            return json(['code' => 504, 'msg' => '公司呢']);exit();
        }
        if(!empty(input("param.expressnum"))){
            $expressnum=input("param.expressnum");
        }else{
            return json(['code' => 505, 'msg' => '单号呢']);exit();
        }
        $data['uexpress']=$expresscom;
        $data['uexpressnum']=$expressnum;
        $data['salesbacktate']=6;
        $collect=Db::name('orders')->where('cus_id',$cus_id)->where('openid',$openid)->where('id',$order_id)->update($data);
        if($collect){
            Db::name('ordersub')->where('cus_id',$cus_id)->where('openid',$openid)->where('of_id',$order_id)->update($data);
            return json(['code' => 200, 'msg' => '申请成功！']);exit();
        }else{
            return json(['code' => 500, 'msg' => '失败！']);exit();
        }

    }
}